﻿using Mapster;
using Nantianmen.Domain.Dtos;
using Nantianmen.Domain.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nantianmen.Domain.Services.Destination
{
    public class DestinationQueryService : IDestinationQueryService
    {
        protected virtual CancellationToken CancellationToken => CancellationToken.None;
        public IDestinationStore DestinationRepository { get; protected set; }

        public DestinationQueryService(IDestinationStore destinationRepository)
        {
            DestinationRepository = destinationRepository;
        }

        public async Task<List<DestinationDto>> ListAllAsync()
        {
            var models = await DestinationRepository.ListAllAsync(CancellationToken);
            return models.Select(model => model.Adapt<DestinationDto>()).ToList();
        }

        public async Task<DestinationDto> FindByIdAsync(string id)
        {
            var model = await this.DestinationRepository.FindByIdAsync(id, CancellationToken);
            return model.Adapt<DestinationDto>();
        }

        public async Task<List<DestinationDto>> FindByAddressAsync(string address)
        {
            var destinations = await this.DestinationRepository.FindByAddressAsync(address, CancellationToken);
            return destinations.Select(d => d.Adapt<DestinationDto>()).ToList();
        }
    }
}
